package com.google.coffeeshop.dao.impl;

import java.io.Serializable;

import com.google.coffeeshop.dao.AbstractBaseDAO;
import com.googlecode.genericdao.dao.jpa.GenericDAOImpl;
import com.googlecode.genericdao.search.Search;

public class AbstractBaseDAOImpl<T, ID extends Serializable> extends GenericDAOImpl<T, ID> implements AbstractBaseDAO<T, ID> {

	@Override
	public ID findLastestId() {
		Search search = new Search(super.persistentClass);
		search.setFirstResult(0);
		search.setMaxResults(1);
		search.addSortDesc("id");
		T t = this.searchUnique(search);
		if (t != null) {
			return (ID)super.getMetadataUtil().getId(t);
		}
		return null;
	}

}
